Imports System.Net.Mail

Partial Public Class pages_orders_usercontrols_UCOrder : Inherits UserControl

#Region "Interface"
    Private m_order As COrder
    Public Sub Display(ByVal [order] As COrder, page As COrderList, pi As CPagingInfo, hideCustomer As Boolean, hideProduct As Boolean)
        If Parent.Controls.Count Mod 2 = 0 Then row.Attributes.Add("class", "alt_row")
        colProduct.Visible = Not hideProduct
        colProduct2.Visible = Not hideProduct
        colCustomer.Visible = Not hideCustomer

        m_order = order

        With [order]
            litNumber.Text = CStr(page.IndexOf([order]) + 1 + pi.PageIndex * pi.PageSize)
            lnkOrderProductId.Text = .ProductName
            lnkOrderProductId.NavigateUrl = CSitemap.ProductEdit(.OrderProductId)
            lnkOrderCustomerId.Text = .CustomerName
            lnkOrderCustomerId.ToolTip = .CustomerEmail
            If lnkOrderCustomerId.Text.Length = 0 Then lnkOrderCustomerId.Text = lnkOrderCustomerId.ToolTip
            lnkOrderCustomerId.NavigateUrl = CSitemap.Customer(.OrderCustomerId)
            litOrderPriceHistorical.Text = .OrderPriceHistorical.ToString("C")
            chkOrderIsPaid.Checked = .OrderIsPaid

            lnkOrderCreated.ToolTip = CUtilities.LongDateTime(.OrderCreated)
            lnkOrderCreated.Text = CUtilities.Timespan(.OrderCreated)
            lnkOrderCreated.NavigateUrl = CSitemap.Order(.OrderId)

            lblType.Text = .Product.TypeName
            'lnkReminders.Text = CUtilities.CountSummary(.ReminderCount, "email", "none")
            'lnkReminders.NavigateUrl = CSitemap.Reminders(.OrderId)

            lnkPayments.Text = CUtilities.CountSummary(.PaymentCount, "payment", "&nbsp;")
            lnkPayments.NavigateUrl = CSitemap.PaymentsForOrder(.OrderId)

            If .PaymentCount > 0 Then
                If .PaymentCount = 1 Then
                    With .Payments(0)
                        lnkPayments.Text = String.Concat(.PaymentTransaction, " (", .PaymentCode, ")")
                    End With
                End If
                litPaid.Text = CTextbox.SetMoney(.PaidAmount)
                litNet.Text = CTextbox.SetMoney(.PaidNet)
                If litPaid.Text <> litOrderPriceHistorical.Text Then
                    litPaid.ForeColor = Drawing.Color.Red
                    litOrderPriceHistorical.ForeColor = Drawing.Color.Red
                    litPaid.ToolTip = "Values should match (unless its a donation)"
                    litOrderPriceHistorical.ToolTip = "Values should match"
                End If
            End If
        End With
    End Sub
#End Region

    Protected Sub btnResend_Click(sender As Object, e As System.EventArgs) Handles btnResend.Click
        Dim o As COrder = m_order

        'Get the email template
        Dim t As CEmailTemplate = CEmailTemplate.Get(EEmailTemplate.Download)

        'Send the mail
        Dim msg As New MailMessage()
        Try
            With msg
                .IsBodyHtml = True
                .To.Add(New MailAddress(o.CustomerEmail, o.CustomerName))
                .Subject = t.ProcessSubject(o.Product, o.Customer)
                .Body = t.Process(o, msg, Nothing)

                '*Sender is downloads.mikeconnellminstries.com (not gmail)
                .ReplyToList.Add(New MailAddress("mikeconnellministries@gmail.com", "Mike Connell Ministries"))
            End With

            With New SmtpClient
                .Send(msg)
            End With
            'CConfig.Gmail.Send(msg)
            msg.Dispose()
        Catch ex As Exception
            SchemaAudit.CAudit_Error.Log(ex, o.CustomerEmail, o.CustomerName)
        End Try
    End Sub
End Class

